import { StoreCreate } from '@shared/interfaces/store'
import { FormGroup, FormBuilder } from '@angular/forms'
import { StoreDataService } from '../store-data.service'

export abstract class StoreNewBaseClass {
  store: StoreCreate

  validateForm: FormGroup

  constructor(
    public fb: FormBuilder,
    public storeStore: StoreDataService,
  ) {
    this.validateForm = this.fb.group({})
    this.initStoreData()
  }

  initStoreData(): void {
    this.storeStore
      .value$
      .subscribe(store => {
        this.store = store
      })
  }

  /* 子类有需要就覆盖 */
  checkValid(): boolean {
    this.pushDataToStore()
    return true
  }

  /* 子类去实现 */
  abstract pushDataToStore(): void
}
